package com.tinyengine.it.controller.db;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.tinyengine.it.common.base.PageQueryVo;
import com.tinyengine.it.common.base.Result;
import com.tinyengine.it.model.entity.SysTermCache;
import com.tinyengine.it.model.vo.SysTermCacheVo;
import com.tinyengine.it.service.db.SysTermCacheService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Tag(name = "系统名词、术语缓存")
@RestController
@RequestMapping("/term/cache")
@Validated
@RequiredArgsConstructor
public class SysTermCacheTypeController {

    private final SysTermCacheService sysTermCacheService;

    @Operation(summary = "获取分页列表")
    @PostMapping("/pages/list")
    public Result<IPage<SysTermCache>> getPageList(@RequestBody PageQueryVo<SysTermCacheVo> system) {
        IPage<SysTermCache> pageList = sysTermCacheService.getPageList(system);
        return Result.success(pageList);
    }


    @Operation(summary = "新增修改")
    @PostMapping("/addUpdate")
    public Result addUpdate(@RequestBody SysTermCache termCache) {
        sysTermCacheService.saveOrUpdate(termCache);
        return Result.success(termCache);
    }

    @Operation(summary = "删除")
    @GetMapping("/del/{id}")
    public Result addUpdate(@PathVariable Long id) {
        sysTermCacheService.removeById(id);
        return Result.success();
    }
}
